<?php
/**
 * 管理员信息
 *
 * @author      姜士镒<1858139@qq.com>
 * @version     V1.0.0.1
 * @since        1.0
 */

namespace Dyadmin\Model;
use Think\Model;

class AdminModel extends Model { 
    
	public function find_login($admin_name, $admin_pwd){
        $result = array(-1, '');
        $where['admin_name'] = $admin_name;
        $where['admin_pwd'] = $admin_pwd;
        $count = M('Dyadmin')->where($where)->count();
        if(1 == $count) {
            $data = M('Dyadmin')->where("admin_name='%s'", $admin_name)->find();
            $login_session = sha1($admin_name.time());
            $result[0] = 'success';
           	$result['login_session'] =$login_session;
           	$result['admin_id'] =$data['admin_id'];
           	$result['admin_name'] =$data['admin_name'];
           	
           	
           	setcookie ( 'login_session', $login_session, 0, '/' );
           	setcookie ( 'admin_id', $data['admin_id'], 0, '/' );
           	setcookie ( 'admin_name',$data['admin_name'], 0, '/' );
           	
           	session ( 'login_session', $login_session );
           	session ( 'admin_id', $data['admin_id'] );
           	session ( 'admin_name',$data['admin_name'] );
           	
           	
           	
            $login_num = $data['login_num'];
            $login_num=$login_num+1;
          
            $dataf = array('login_time'=>time(),'login_num'=>$login_num,'login_session'=>$login_session);

            M('Dyadmin')-> where("admin_name='%s'", $admin_name)->setField($dataf);
//            D('LogAdmin')->insert_log('管理员登入');
            
        } 
        return $result;
    }
    
   public function  isLogin($login_session){
   	$data =null;
   	if(!empty($login_session)){
   		
   		$where['login_session'] = $login_session;
   		$data = M('Dyadmin')->where($where)->find();
   		
   	}
   	return $data;
   	
   	
   }
    
   
}